package cn.wolfcode.Controller;

import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.domain.SystemDictionaryItem;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.DepartmentService;
import cn.wolfcode.service.SystemDictionaryService;
import cn.wolfcode.util.RequirePermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {

    @Autowired
   private SystemDictionaryService systemDictionaryService;
   




//    @RequestMapping("/list")
//    public String listAll(Model model){
//        List<SystemDictionaryItem> departments = departmentMapper.selectAll();
//        model.addAttribute("departments",departments);
//        return "systemDictionaryItem/list";
//    }

    @RequirePermission(name = "查看字典目录",experssion = "systemDictionaryItem:list")
    @RequestMapping("/list")
    public String listAll(Model model,QueryObject queryObject){
        System.out.println(queryObject);
        PageInfo<SystemDictionary> pageInfo = systemDictionaryService.listPage(queryObject);
        model.addAttribute("pageInfo",pageInfo);
        return "systemDictionary/list";
    }

    @RequirePermission(name = "字典目录删除",experssion = "systemDictionaryItem:delete")
    @RequestMapping("/delete")
    public String delete(Long id){
        if (id != null){
            systemDictionaryService.deleteByPrimaryKey(id);
        }
        return "redirect:/systemDictionary/list";
    }

//    @RequestMapping("/input")
//    public String input(Long id,Model model){
//        if (id != null){
//            SystemDictionaryItem systemDictionaryItem = departmentService.selectByPrimaryKey(id);
//            model.addAttribute("systemDictionaryItem", systemDictionaryItem);
//        }
//        return "systemDictionaryItem/input";
//    }
@RequirePermission(name = "字典目录权限新增/编辑",experssion = "systemDictionaryItem:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(SystemDictionary systemDictionary,Model model){
        if (systemDictionary.getId() != null){
            systemDictionaryService.updateByPrimaryKey(systemDictionary);
        }else {
            systemDictionaryService.insert(systemDictionary);
        }
        return "redirect:/systemDictionary/list";
    }


}

